<?php
namespace App\Services\Admin;

use App\Jobs\Fun;
use App\Repositories\Admin\NewsRepository;

class NewsService
{
    private $service;

    public function __construct()
    {
        $this->service = new NewsRepository();
    }

    public function getIndex()
    {
        return $this->service->getIndexList();
    }

    public function getIndexByCid($uid,$page)
    {
        $models = $this->service->getIndexByCid($uid,$page);
        if (!count($models)) { return array(); }
        //外发订单状态
        $lastDay = strtotime(date('Ymd',time()).' 000000') ; //当前时间
        foreach ($models as $model) {
            if ($model->created_at > $lastDay) {
                $model->statusName = '最新发布';
                $model->timestatus = 'new';
            } else {
                $model->statusName = '已发布';
                $model->timestatus = 'old';
            }
            $model->thumb= \App\Jobs\Fun::pImg($model->thumb);
          //  $model->time=Fun::date($model->created_at);
        }
        return $models;
    }

    public function add($data)
    {
        return $this->service->setAdd($data);
    }

    public function modify($data,$id)
    {
        return $this->service->setModify($data,$id);
    }

    public function getOne($id)
    {
        return $this->service->getShowOne($id);
    }
}